package com.zjj.controller;

import com.zjj.entity.Dish;
import com.zjj.entity.R;
import com.zjj.service.DishService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/dish")
@Tag(name = "菜品控制器",description = "菜品接口")
public class DishController {
    @Autowired
    private DishService dishService;

    // 分页展示菜品
    @GetMapping
    @Operation(summary = "分页展示菜品",description = "分页展示菜品接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R selectById(@Parameter(description = "页码") Integer page ,@Parameter(description = "分类id") Integer categoryId
            ,@Parameter(description = "菜品名称") String name , @RequestParam(defaultValue = "10") Integer size){
            return dishService.selectPage(page,size,categoryId,name);
    }

    // 添加菜品
    @PostMapping
    @Operation(summary = "新增菜品",description = "新增菜品接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R insert(@Parameter(description = "菜品信息") @RequestBody Dish dish){
        return dishService.insert(dish);
    }

    // 删除菜品信息
    @DeleteMapping("/{id}")
    @Operation(summary = "删除菜品",description = "删除菜品接口")
    @ApiResponses(value = {@ApiResponse(responseCode = "200",description = "成功"),
            @ApiResponse(responseCode = "404",description = "失败")})
    public R delete(@Parameter(description = "菜品id") @Validated @PathVariable("id") Integer id){
        return dishService.delete(id);
    }
}
